
package at.ac.tuwien.sepm.s2011.e0208329.services;

import java.sql.SQLException;
import java.util.ArrayList;

import at.ac.tuwien.sepm.s2011.e0208329.dao.DAOFactoryImpl;
import at.ac.tuwien.sepm.s2011.e0208329.dao.DienstleistungDAOImpl;
//import at.ac.tuwien.sepm.s2011.e0208329.db.DatabaseManager;
import at.ac.tuwien.sepm.s2011.e0208329.domain.Dienstleistung;

/**
 * this class offer the service-calling to DienstleistungDAO, 
 * and offer all manage functions to table "Dienstleistung"
 * @author YAN KUN
 *
 */
public class MyCarServicesImpl implements MyCarServices {
	private DienstleistungDAOImpl serviceDAO;
	public static MyCarServicesImpl refServices;

	/**
	 * @param serviceDAO
	 * @param dbm
	 */
	public MyCarServicesImpl() {// Constructor
		super();
		serviceDAO = DAOFactoryImpl.getDAOFactory().getServiceDAO(); // initialize a DienstleistungDAO
	}

	@Override
	public ArrayList<Dienstleistung> getAllServices() throws SQLException { // call the initialized DienstleistungDAO's 
		                                                                    // getAllServices()
		return serviceDAO.getAllServices();				
	}
	
	public static MyCarServicesImpl getInstance() { // getter for refServices
	    if(refServices == null){
	    	refServices = new MyCarServicesImpl();
	    }
	    return refServices;
	}

	@Override
	public void createService(Dienstleistung ser) throws SQLException { // call the initialized DienstleistungDAO's 
        																// insertServices(Dienstleistung ser)
		serviceDAO.insertService(ser);
	}

	@Override
	public void deleteService(int serID) throws SQLException {// call the initialized DienstleistungDAO's 
															  // delete(int sericeID)
		serviceDAO.deleteService(serID);
	}

	@Override
	public int getServiceID(String serviceName) throws SQLException {// call the initialized DienstleistungDAO's 
		  															 // getServiceID(String serviceName)
		return serviceDAO.getServiceID(serviceName);
	}

	@Override
	public int getServicePrice(int serID) throws SQLException {// call the initialized DienstleistungDAO's 
			 												   // getServicePrice(String serviceID)
		return serviceDAO.getPrice(serID);
	}

	@Override
	public String getSerName(int serID) throws SQLException {// call the initialized DienstleistungDAO's 
															 // getServiceName(String serviceID)
		return serviceDAO.getSerivceName(serID);
	}

}
